package com.atguigu.lease.common.context;

/**
 * @author Tsuchi
 * @description TODO
 * @date 2024/12/25 14:20
 */

// 本地线程存储 用于把token设置到本地存储
public class LoginUserContext {
	private static final ThreadLocal<LoginUser> userThreadLocal = new ThreadLocal<>();

	// 设置用户信息到ThreadLocal中
	public static void setLoginUser(LoginUser loginUser) {
		userThreadLocal.set(loginUser);
	}

	public static LoginUser getLoginUser() {
		return userThreadLocal.get();
	}


	// 删除数据 避免长期占用内存
	public static void clear() {
		userThreadLocal.remove();
	}
}
